home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d18 / tpa2_a.arc / HEXBYTE.PAS < prev    next >
Pascal/Delphi Source File  |  1991-04-28  |  2KB  |  70 lines

  1. {═══════════════════════════ HEXBYTE.PAS ════════════════════════════}
  2. { Usage:  Hexbyte            (From Editor, just Run)                 }
  3. {═══════════════════════════ HEXBYTE.PAS ════════════════════════════}
  4. {- This demonstration illustrates the use of TP&Asm and Turbo Pascal }
  5. {- to develop and verify an assembly language procedure intended for }
  6. {- stand-alone assembly.  The assembly code at 'Hexbyte:' returns    }
  7. {- (in AX) a Word containing the 2-byte Ascii representation of the  }
  8. {- byte value passed to it in Al.  Use Pascal to Call Hexbyte (via   }
  9. {- the Pascal function TestHexByte) and print the result for every   }
  10. {- possible input value.                                             }
  11.  
  12.  
  13. {════════════════════════════ TestHexByte ═══════════════════════════}
  14. {  Pascal Function containing the code to be tested.                 }
  15. {════════════════════════════ TestHexByte ═══════════════════════════}
  16. FUNCTION TestHexByte(SourceByte: BYTE): INTEGER;
  17. {- In our assembly routine it will be convenient to get the -}
  18. {- parameter from Al and to leave the Result in Ax.         -}
  19. CONST
  20.   HexDigits: ARRAY[0..15] OF CHAR = '0123456789ABCDEF';
  21.  
  22. BEGIN
  23.  
  24. Assemble
  25.  
  26.   Mov Al,SourceByte  ; Get parameter
  27.   Call HexByte       ; Call ASSEMBLY procedure
  28.   Mov TestHexByte,Ax ; Put in TestHexByte Function Result
  29.   Jmp Finish         ; and Exit
  30.  
  31.  ;- Here is the precise code we will use in our assembly program -
  32.  ;- Assumes Al = SourceByte on entry, Returns result in Ax
  33.  ;- All other registers are preserved
  34. HexByte:
  35.   Push Bx
  36.   Xor Ah,Ah  ; set Ah = 0 to prevent Divide Overflow
  37.   Mov Bl,010
  38.   Div Bl     ; Al = Quo, Ah = Rem
  39.   Mov Bx,Offset HexDigits
  40.   Xchg Al,Ah
  41.   XlatB
  42.   Xchg Al,Ah
  43.   XlatB
  44.   Pop Bx
  45.   Ret
  46.  ;- End of HexByte code
  47.  
  48.  
  49. Finish:
  50. END; {Assemble}
  51.  
  52. END; {FUNCTION TestHexByte}
  53.  
  54. CONST Result: RECORD
  55.         Len: BYTE;
  56.         Wrd: INTEGER;
  57.       END = (Len:2;Wrd:0);
  58. VAR
  59.   n: BYTE;
  60.   ResultString: STRING[2] Absolute Result;
  61.  
  62. BEGIN {Main Program}
  63.   FOR n := 0 TO 255 DO BEGIN
  64.     WRITE(n:3,' ');
  65.     Result.Wrd := TestHexByte(n);
  66.     WRITE(ResultString,'  ');
  67.   END; {FOR n := 0 TO 255 DO }
  68.   WRITELN;
  69. END. {Main}
  70.